package april.example.fastjson;

import java.util.ArrayList;

import com.alibaba.fastjson.JSON;

public class Serialize {

	public static void main(String[] args) {
		Group admin = new Group();

		User guest = new User();
		guest.setId(1L);
		guest.setName("guest");

		User root = new User();
		root.setId(2L);
		root.setName("root");

		ArrayList<User> users = new ArrayList<User>();
		users.add(guest);
		users.add(root);

		admin.setId(1L);
		admin.setName("admin");
		admin.setUsers(users);

		String jsonString = JSON.toJSONString(admin);
		System.out.println(jsonString);

		Group group = JSON.parseObject(jsonString, Group.class);
		System.out.println(group.getId() + " " + group.getName());
	}
}
